__author__ = "Chengye zhao (chengyezhao@gmail.com)"

from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

from product import Product, getProductCategory
from history import History

import logging

class UpdateCategoryJob(webapp.RequestHandler):
	def get(self):
		q = db.GqlQuery("SELECT * FROM Product where category = null")
		for product in q:
			product.category = getProductCategory(product.title)
			product.put()

		q = db.GqlQuery("SELECT * FROM History where category = null")
		for product in q:
			product.category = getProductCategory(product.title)
			product.put()

application = webapp.WSGIApplication(
	[('/update_category', UpdateCategoryJob)],
	debug=True)

def main():
	run_wsgi_app(application)

if __name__ == "__main__":
	main()
